<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <lk-box></lk-box>
    </div>
    

    <script src="../js/vue.js"></script>

    <script>

      //定义子组件1
      const LiBtn = {
        data(){
          return {
            abc : 'abc',
            count:0
          }         
        },
        template:`
          <button @click="btnClick">点击{{count}}次,我是子组件1</button>
        `,
        methods: {
          btnClick(){
            //子组件获取父组件的内容
            
            console.log(this.$parent);//父组件
            console.log(this.$parent.abc);//父组件的数据
            this.$parent.abc = 789;
            console.log(this.$parent.abc);
            console.log(this.$parent.$parent.abc);//爷爷组件的数据
            console.log(this.$root.abc);//根组件的数据

          }
        },
      };

      const Box = {
        data(){
          return {
            abc : "123"
          }
        },
        template:`
        <div style="height: 200px; width: 200px; background-color: bisque;">
          <li-btn></li-btn>        
        </div>
        `,
        components:{
          'li-btn':LiBtn//要用租件就必须注册组件才能使用
        }
      }

      //全局
      const app = Vue.createApp({
        data() {
          return {
            abc: "456"
          }
        },
        components:{
          'lk-box':Box
        }
      }).mount("#app");
    </script>
  </body>
</html>